package com.cpit.qualitycontrol.dao;


import com.cpit.qualitycontrol.entity.Device;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;


public interface DeviceRepository extends JpaRepository<Device, String>, JpaSpecificationExecutor<Device> {

    Device save(Device device);

    Device findByName(String name);

    Device findById(String id);

    @Override
    void delete(String s);

    Page<Device> findByNameContaining(String name, Pageable pageable);

    Page<Device> findAll(Pageable pageable);

    Page<Device> findAll(Specification<Device> var1, Pageable var2);

    @Query("select p.name from Device d , Project p where d.id = ?1 and d.projectId = p.id")
    String findProjectNameById(String deviceId);

    @Query("select d.addrs from Device d where d.id = ?1")
    String findDeviceAddrsById(String deviceId);
    List<Device> findByProjectId(Long projectId);

    Long countByDeviceTypeId(Long deviceTypeId);
}
